<template>
  <div>
    <div style="text-align: center">
      <el-form :inline="true" :model="dataForm" ref="dataForm" @keyup.enter.native="getDataList()" size="mini" label-width="150px">
        <el-form-item label="申请姓名：">
          <el-input v-model="dataForm.search" placeholder="申请姓名" clearable></el-input>
        </el-form-item>
        <el-form-item label="申请手机号：">
          <el-input v-model="dataForm.mobliePhone" placeholder="申请手机号" clearable></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div style="text-align: center">
      <el-button @click="getDataList()" size="mini" type="primary">查询</el-button>
      <el-button @click="reset()" size="mini">重置</el-button>
    </div>
    <hr/>
    <div style="margin-bottom: 5px;margin-top: 5px">
      <el-button @click="obtainTask()" size="mini" type="primary">获取任务</el-button>
    </div>

    <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;border-radius: 5px;" size="mini" class="width-bg"
              border tooltip-effect="dark" :header-cell-style="{background:'#eef1f6',color:'#606266'}">
      <el-table-column type="selection" header-align="center" align="center" width="50">
      </el-table-column>
      <el-table-column prop="name" header-align="center" align="center" label="名称">
      </el-table-column>
      <el-table-column prop="mobliePhone" header-align="center" align="center" label="手机号">
      </el-table-column>
      <el-table-column prop="processId" header-align="center" align="center" label="流程实例号">
      </el-table-column>
      <el-table-column prop="taskId" header-align="center" align="center" label="任务号">
      </el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="开始时间">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="280" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="viewImage(scope.row)">查看流程图</el-button>
          <el-button type="text" size="small" @click="handleBusiness(scope.row)">业务处理</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <view-flow v-if="viewFlowVisible" ref="viewFlowRef" @viewFlowColse="viewFlowColse"></view-flow>

    <task-details :flowDetails="flowDetails" @closeTaskDetails="closeTaskDetails" :taskDatailsVisible="taskDatailsVisible"></task-details>

    <assign-flow-task :assignTasksVisible="assignTasksVisible" @closeAssignTask="closeAssignTask"></assign-flow-task>
  </div>
</template>

<script>
    import { applyTasksPage } from '@/api/flow';
    import ViewFlow from './viewFlow'
    import  TaskDetails from "./taskDetails";
    import AssignFlowTask from "./assignFlowTask";

    export default {
        data () {
            return {
                dataForm: {
                    search:'',
                    mobliePhone:''
                },
                dataList: [],
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                dataListLoading: false,
                dataListSelections: [],
                addOrUpdateVisible: false,
                viewFlowVisible:true,
                flowDetails:null,
                taskDatailsVisible:false,
                assignTasksVisible:false
            }
        },
        components: {
            ViewFlow,
            TaskDetails,
            AssignFlowTask
        },
        activated () {
            this.getDataList()
        },
        methods: {
            // 获取数据列表
            getDataList () {
                this.dataListLoading = true
                const param= {
                    'current': this.pageIndex,
                    'size': this.pageSize,
                    'condition': this.dataForm
                }
                const requestData={
                    'data':param
                }
                applyTasksPage(requestData).then((res)=>{
                    this.dataListLoading = false
                    if(res.code=='0000'){
                        this.dataList = res.data.records
                        this.totalPage = res.data.total
                    }else{
                        this.dataList = []
                        this.totalPage = 0
                    }
                }).catch((err)=>{

                })
            },
            // 每页数
            sizeChangeHandle (val) {
                this.pageSize = val
                this.pageIndex = 1
                this.getDataList()
            },
            // 当前页
            currentChangeHandle (val) {
                this.pageIndex = val
                this.getDataList()
            },
            // 多选
            selectionChangeHandle (val) {
                this.dataListSelections = val
            },
            viewImage (row) {
                this.viewFlowVisible=true;
                this.$nextTick(() => {
                    this.$refs.viewFlowRef.init(row.processId,row.name)
                })
            },
            handleBusiness(row){
                this.taskDatailsVisible=true
                this.flowDetails=row
            },
            reset(){
                this.dataForm.search=null
                this.dataForm.mobliePhone=null
                this.pageIndex = 1
                this.getDataList()
            },
            viewFlowColse(){
                this.viewFlowVisible=false;
            },
            closeTaskDetails(){
                this.taskDatailsVisible=false
            },
            closeAssignTask(){
                this.assignTasksVisible=false
            },
            obtainTask(){
                this.assignTasksVisible=true
            }
        }
    }
</script>
